const TypeDao = require("../dao/type/type_dao.js");
const StaffDao = require("../dao/staff/staff_dao.js");

const SectionService = {
    findDepartment(req,res,next){

        TypeDao.find({})
             .then((data)=>{
                res.json({
                                    res_code: 1,
                                    res_error: "",
                                    res_body: {
                                        status: 1,
                                        data: data
                                    }
                                });
             })
             .catch((err) => {
                                res.json({
                                    res_code: 0,
                                    res_error: err,
                                    res_body: {}
                                });
                            });
    },
    findByDepartment(req,res,next){
         const {department} = req.query;
         console.log(req.query);
         console.log(department);
         StaffDao.find({department})
                .then((data)=>{
                        res.json({
                                    res_code: 1,
                                    res_error: "",
                                    res_body: {
                                        status: 1,
                                        data: data
                                    }
                                });
             })
             .catch((err) => {
                                res.json({
                                    res_code: 0,
                                    res_error: err,
                                    res_body: {}
                                });
                            });
    },
    findByPage(req, res, next) {

        const {page} = req.query;
        console.log({page});
        StaffDao.findByPage(page)
                            .then((data) => {
                                res.json({
                                    res_code: 1,
                                    res_error: "",
                                    res_body: {
                                        status: 1,
                                        list: data
                                    }
                                });
                            })
                            .catch((err) => {
                                res.json({
                                    res_code: 0,
                                    res_error: err,
                                    res_body: {}
                                });
                            });
    },


}
module.exports = SectionService;